{% load thumbnail i18n %}
{% if forloop.parentloop.last and forloop.parentloop.first %}
    <li id="{{ inline_admin_formset.formset.prefix }}-empty" class="span2 add-row">
        <div class="thumbnail">
            <img src="http://www.placehold.it/160x120/EFEFEF/AAAAAA&text={% trans 'Add new' %}" >
        </div>
    </li>
{% endif %}

{% if not forloop.parentloop.last %}
    {% for line in fieldset %}
        {% if forloop.first %}
            {% if forloop.parentloop.parentloop.first %}
            <li id="{{ inline_admin_formset.formset.prefix }}-empty" class="span2 add-row">
                <div class="thumbnail">
                    <img src="http://www.placehold.it/160x120/EFEFEF/AAAAAA&text={% trans 'Add new' %}">
                </div>
            </li>
            {% endif %}
            <li class="span2" 
                {% if not forloop.parentloop.parentloop.last %}
                rel="tooltip" data-placement="bottom" title="{{ inline_admin_form.form.description.value }}"
                data-toggle="collapse" 
                data-target="#{{ inline_admin_formset.formset.prefix }}-{% if not forloop.parentloop.parentloop.last %}{{ forloop.parentloop.parentloop.counter0 }}{% else %}empty{% endif %}"
                {% endif %}
            >
                <div class="thumbnail">
        {% endif %}
        {% for field in line %}
            {% if field.field.value %}
                {% if field.field.name == 'photo' %}
                    {% thumbnail field.field.value "160x120" crop="center" as img %}
                        <img src="{{ img.url }}" width="{{ img.width }}" height="{{ img.height }}" />
                    {% endthumbnail %}
                    
                {% endif %}
            {% endif %}

        {% endfor %}
        {% if forloop.last %}
                </div>
            </li>
        {% endif %}

    {% endfor %}
{% endif %}